這 綜合 R 倉儲網路(CRAN) 是一個全球性的集中式、同行審查伺服器網路,提供超過 19,000 個套件。它透過跨多樣硬體的嚴謹測試流程,確保架構完整性。
1. 庫與倉儲之間的差異
區分這兩者至關重要: CRAN 是基於網頁的 倉儲 (來源),而你的 套件庫 是你本地磁碟上實際安裝套件的資料夾。指令 library() 會將已安裝的程式碼載入到你目前的作業環境中。
2. 內省檢視與原生資源
R 提供工具讓你檢視套件內部結構。 system.file() 可取得套件資源(如文件或資料集)的完整路徑,而 file.show() 則會呈現這些資源。基礎版 R 預設包含 datasets 套件,以及「推薦」套件,例如 boot (用於拔靴法與統計重抽樣)。
main.py
TERMINALbash — 80x24
> Ready. Click "Run" to execute.
>
QUESTION 1
What is the technical difference between CRAN and a 'Library' in R?
CRAN is for documentation, Library is for code.
CRAN is the remote repository; Library is the local directory of installed packages.
They are synonymous terms for the search path.
Library is a sub-folder within the CRAN server.
✅ Correct!
Correct! You download from CRAN to your local Library.❌ Incorrect
CRAN acts as the global distribution network, whereas the Library is your local physical storage.QUESTION 2
Which function allows you to programmatically query all available tools on CRAN?
available.packages()installed.packages()show.cran()library(all)✅ Correct!
available.packages() (the successor to the CRAN.packages concept) queries the repository metadata.❌ Incorrect
installed.packages() only looks at your local disk; available.packages() queries the remote repository.QUESTION 3
What is the primary use of
system.file()?To delete temporary system files.
To find the physical file path of an installed package's assets.
To execute a system terminal command.
To download files from the internet.
✅ Correct!
It is an introspection tool that finds the full path to a file within a specific package.❌ Incorrect
It doesn't execute files; it finds their location on your hardware.QUESTION 4
Which of these packages is considered 'Recommended' and included by default in R distributions?
ggplot2tidyversebootshiny✅ Correct!
The boot package is part of the 'Recommended' tier, maintained alongside the core engine.❌ Incorrect
While popular, ggplot2 and tidyverse are third-party packages that must be explicitly installed.QUESTION 5
What does the
datasets package provide to the R ecosystem?A standard for SQL connectivity.
A collection of built-in data frames for testing and learning.
An interface for cloud storage.
Tools for data cleaning only.
✅ Correct!
It provides 'common language' data like mtcars and iris.❌ Incorrect
It is a repository of sample data frames, not a functional utility for cleaning or SQL.Case Study: Package Compliance Audit
Institutional Documentation Verification
A researcher needs to verify the version and license of the 'boot' package to ensure it meets institutional compliance before using it in a published clinical trial.
Q
What sequence of commands would locate and display the 'DESCRIPTION' file for the 'boot' package?
Solution:
First, load the package with
First, load the package with
library(boot). Then, locate the file path using path <- system.file('DESCRIPTION', package='boot')file.show(path).Q
Why is it better to use
system.file() rather than a hardcoded file path like 'C:/R/library/...'?Solution:
R libraries can be installed in different locations depending on the OS (Windows vs Mac) and user permissions.
R libraries can be installed in different locations depending on the OS (Windows vs Mac) and user permissions.
system.file() dynamically resolves the correct path regardless of the machine's configuration, ensuring code portability.